package com.dstats.sync;

import android.content.Context;

import com.dstats.network.JsonReader;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by MeSeems - Note 1 on 22/01/2015.
 */
public class SyncAll extends SyncAbstractModel{

    private AtomicInteger mPullCounter;


    SyncAll(Context context) {
        super(context);
        mPullCounter = new AtomicInteger(0);
    }

    private void decrementAndCheck(){
        int qnty = mPullCounter.decrementAndGet();
        if (qnty == 0) {
            onPullFinish(null, 0);
        }
    }

    @Override
    protected void onPull() {
        mPullCounter.incrementAndGet();
        new SyncHero(getContext()){
            @Override
            public void onPullFinish(JsonReader response, Object result) {
                super.onPullFinish(response, result);
                decrementAndCheck();
            }
        }.pull();
    }

    @Override
    protected void onPush() {

    }

    @Override
    protected ResultHolder saveResponse(JsonReader jsonReader) {

        return null;
    }

    @Override
    public void onServerError(JsonReader response) {

    }
}
